package com.xrui.hbase.model;

import java.util.Objects;

public class FieldKey<T> {
    /**
     * Name of the field key
     */
    private final String name;
    /**
     * Type of the field key
     */
    private final Class<T> type;

    private FieldKey(String name, Class<T> type) {
        this.name = name;
        this.type = type;
    }

    /**
     * Create a new FieldKey from the given name and type.
     *
     * @param name of the field key
     * @param type of the field key
     * @return a new FieldKey with the given name and type
     */
    @SuppressWarnings("unchecked")
    public static FieldKey create(String name, Class type) {
        return new FieldKey(name, type);
    }

    /**
     * Returns {@code true} if the arguments are equal to each other
     * and {@code false} otherwise.
     *
     * @param object an object to be compared with this {@code FieldKey} for equality
     * @return {@code true} if the argument is equal to this {@code FieldKey}
     * and {@code false} otherwise
     */
    public boolean equals(Object object) {
        if (!(object instanceof FieldKey)) {
            return false;
        }
        FieldKey another = (FieldKey) object;
        return Objects.equals(another.name, name);
    }

    @Override
    public String toString() {
        return name;
    }

    @Override
    public int hashCode() {
        return name.hashCode();
    }

    public String getName() {
        return name;
    }

    public Class<T> getType() {
        return type;
    }
}
